﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KinectGame;

namespace MemoGame
{
    public partial class FinalizeDialog : KinectBaseForm
    {
        public FinalizeDialog(String timeSpent)
        {
            InitializeComponent();
            Game game = Game.getInstance();
            HallOfFame hallOfFame = game.HallOfFame;
            hallOfFame.addItem(game.GameSize, game.Login, timeSpent);
            hallOfFame.saveRanking();
            initHOF(game.GameSize);
            label1.Text = "Time needed: " + timeSpent; 
        }
        
        public override void SetupForKinectMode()
        {
            base.SetupForKinectMode();
            this.btnMenu.Highlight();
            this.btnMenu.Click -= new System.EventHandler(this.btnMenu_Click);
        }

        public override int SetHorizontalItemNumber()
        {
            return 1;
        }

        public override int SetVerticalItemNumber()
        {
            return 1;
        }

        private void btnMenu_Click(object sender, EventArgs e)
        {
            OpenMenu();
        }

        private void OpenMenu()
        {
            this.gameContext.ApplicationMode(this, new MenuUI(), 0);
        }
        public override void Click(int horizontalIndex, int verticalIndex)
        {
            OpenMenu(); 
        }

        private void initHOF(int index)
        {
            HallOfFame hof = Game.getInstance().HallOfFame;
            hof.Ranking.Clear();
            hof.fillRanking();
            hof.Ranking[index].Sort();

            for (int i = 1; i <= 10; i++)
            {
                if (hof.Ranking[index].Count < i)
                {
                    hof.Ranking[index].Add(new HOFItem("", ""));
                }
            }

            name1.Text = hof.Ranking[index].ElementAt(0).Player;
            name2.Text = hof.Ranking[index].ElementAt(1).Player;
            name3.Text = hof.Ranking[index].ElementAt(2).Player;
            name4.Text = hof.Ranking[index].ElementAt(3).Player;
            name5.Text = hof.Ranking[index].ElementAt(4).Player;
            name6.Text = hof.Ranking[index].ElementAt(5).Player;
            name7.Text = hof.Ranking[index].ElementAt(6).Player;
            name8.Text = hof.Ranking[index].ElementAt(7).Player;
            name9.Text = hof.Ranking[index].ElementAt(8).Player;
            name10.Text = hof.Ranking[index].ElementAt(9).Player;
            score1.Text = hof.Ranking[index].ElementAt(0).Time;
            score2.Text = hof.Ranking[index].ElementAt(1).Time;
            score3.Text = hof.Ranking[index].ElementAt(2).Time;
            score4.Text = hof.Ranking[index].ElementAt(3).Time;
            score5.Text = hof.Ranking[index].ElementAt(4).Time;
            score6.Text = hof.Ranking[index].ElementAt(5).Time;
            score7.Text = hof.Ranking[index].ElementAt(6).Time;
            score8.Text = hof.Ranking[index].ElementAt(7).Time;
            score9.Text = hof.Ranking[index].ElementAt(8).Time;
            score10.Text = hof.Ranking[index].ElementAt(9).Time;
        }
    }
}
